{include file="common/head"/}
<script type="text/javascript" src="__STATIC__/common/js/jquery.2.1.1.min.js"></script>
<style>
    .layui-btn-xs{
    height: 22px;
    line-height: 22px;
    padding: 0 5px;
    font-size: 12px;}
    #tb-box{display: none;}
</style>
<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">

    <div class="layui-tab layui-tab-brief" id="table-box">
        <ul class="layui-tab-title">
            <a href="{:url('index')}"><li>返回列表</li></a>
            <li class="layui-this">{$title}</li>
            <li onclick="fromAtion('dateilList','{$course_id}')">课程详情</li>
        </ul>
    </div>

    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">选择栏目</label>
            <div class="layui-input-4">
                <input type="text" id="getCat" placeholder="选择栏目名称" lay-verify="required" value="{$catInfo.name}" class="layui-input">
                <input type="hidden" name="cat_id" id="getCatid" value="{$catInfo.cate_id}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">课程名称</label>
            <div class="layui-input-4">
                <input type="text" name="course_name" ng-model="field.course_name" lay-verify="required" placeholder="{:lang('pleaseEnter')}课程名称" class="layui-input">
            </div>
        </div>

        <!-- 封面图片 -->
        <div class="layui-form-item">
            <label class="layui-form-label">课程封面</label>
            <input type="hidden" name="pic" id="pic" value="{{field.pic}}">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="adBtn"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="adPic">
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">原价</label>
                <div class="layui-input-inline">
                    <input type="tel" name="market_price" ng-model="field.market_price" placeholder="请输入价格￥"  autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">最终价格</label>
                <div class="layui-input-inline">
                    <input type="tel" name="price" ng-model="field.price"  placeholder="请输入价格￥" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <!--<div class="layui-form-item">
            <label class="layui-form-label">是否审核</label>
            <div class="layui-input-block">
                <input type="radio" name="open" ng-model="field.open" ng-checked="field.open==1" ng-value="1" title="{:lang('open')}">
                <input type="radio" name="open" ng-model="field.open" ng-checked="field.open==0" ng-value="0" title="{:lang('close')}">
            </div>
        </div>-->

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">摘要描述</label>
            <div class="layui-input-block">
                <textarea ng-model="field.remark" placeholder="摘要描述" name="remark" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">课程详细</label>
            <div class="layui-input-block">
                <textarea id="content" style="display: none;" ng-model="field.content"   placeholder="课程详细"></textarea>
                <!--<textarea ng-model="field.content" placeholder="课程详细" name="content" class="layui-textarea"></textarea>-->
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">{:lang('order')}</label>
            <div class="layui-input-2">
                <input type="text" name="sort" ng-model="field.sort" value="" placeholder="从小到大排序" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="course_id" value="{$course_id}">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}
<script src="__STATIC__/common/js/angular.min.js"></script>
<script>

    function fromAtion(action,id){
       if(id == ''){
           layer.alert('请先添加课程!');
           return false;
       }else{
           var url = action+"?course_id="+id+"&long=0";
           location.href = "{:url('"+url+"')}";
       }
    }

    var m = angular.module('hd',[]);
    m.controller('ctrl',['$scope',function($scope) {
        $scope.field = '{$info}'!='null'?{$info}:{sort:50,pic:'',content:''};
        layui.use(['form', 'layer','upload','layedit','table'], function () {
            var form = layui.form, $ = layui.jquery,layedit = layui.layedit, upload = layui.upload,table = layui.table;
            if($scope.field.pic){
                adPic.src = "__PUBLIC__"+ $scope.field.pic;
            }

            //富文本编辑图片上传操作
            layedit.set({
                uploadImage: {
                    url: '{:url("UpFiles/editUpload")}' //接口url
                }
            });

            //设定一个富文本编辑器
            var index = layedit.build('content'); //建立编辑器


            //表单提交操作
            form.on('submit(submit)', function (data) {
                // 提交到方法 默认为本身
                data.field.content = layedit.getContent(index);  //获取富文本内容
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("", data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            });

            //选择栏目类型
            $('#getCat').click(function(){
                layer.open({
                    type: 2,
                    title: '选择项目类型',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['70%', '80%'],
                    content: "__URL__/getCat"
                });
            });

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#adBtn'
                ,url: '{:url("UpFiles/upload",array("filename"=>"online_course"))}'
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $('#adPic').attr('src', result); //图片链接（base64）
                    });
                },
                done: function(res){
                    if(res.code>0){
                        $('#pic').val(res.url);
                    }else{
                        //如果上传失败
                        return layer.msg('上传失败');
                    }
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });

        });
    }]);
</script>